package main

// 类型断言

import "fmt"

type MyInterface interface {
	M1()
}

type T int

func (T) M1() {
	fmt.Println("T's M1")
}

func main() {
	var t T
	var i interface{} = t
	v1, ok := i.(MyInterface) // ok = true
	if !ok {
		panic("the type of i is not MyInterface")
	}
	// v1.M1()
	fmt.Printf("the type of v1 is %T\n", v1) // main.T

	i = int64(13)
	v2, ok := i.(MyInterface)                // ok = false
	fmt.Printf("the type of v2 is %T\n", v2) // <nil>
	// v2 = 13

	// var val string = "sss"
	// v3, ok := val.(MyInterface)

	// var mi MyInterface = t
	// v4, ok := mi.(MyInterface)
}
